package com.demo.dao.mapper;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.DELETE_FROM;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.demo.model.Message;

public class MessageMapper {

	public String insert(Message message) {
		return "insert into message (content) values (#{content})";
	}

	public String select() {
		return "select * from message order by id desc";
	}

	public String selectOne(Long id) {
		return "select * from message where id=#{id}";
	}

	public String update(Message message) {
		BEGIN();
		UPDATE("message");
		if (message.getContent() != null && message.getContent().length() > 0) {
			SET("content=#{content}");
		}
		WHERE("id=#{id}");
		String sql = SQL();
		System.out.println(sql);
		return sql;
	}
	
	 public String delete(Long id) {
	        BEGIN();
	        DELETE_FROM("Message");
	        WHERE("id=#{id}");
	        return SQL();
	    }

}
